package com.showsu.editor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.showsu.editor.dao.TblXhsEditorTemplateTitleMapper;
import com.showsu.editor.entity.po.TblXhsEditorTemplateTitle;
import com.showsu.editor.service.IXhsEditorTemplateTitleService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;

/**
 * @Author: jph
 * @Description: 编辑器-模版-标题模版表
 * @Date: Created in 14:54 下午 2025/02/08
 * @Modified By:
 */
@Service
@Slf4j
public class XhsEditorTemplateTitleServiceImpl extends ServiceImpl<TblXhsEditorTemplateTitleMapper, TblXhsEditorTemplateTitle> implements IXhsEditorTemplateTitleService {

    @Autowired
    private TblXhsEditorTemplateTitleMapper mapper;
    @Override
    public List<TblXhsEditorTemplateTitle> queryByTags( List<String> tags) {
        if (CollectionUtils.isEmpty(tags)) {
            return null;
        }
        LambdaQueryWrapper<TblXhsEditorTemplateTitle> wrapper=new QueryWrapper<TblXhsEditorTemplateTitle>().lambda();
        if(!CollectionUtils.isEmpty(tags)){
            wrapper.and(wrapper1->{
                int c=0;
                for(int i=0;i<tags.size();i++){
                    String tag=tags.get(i);
                    if(StringUtils.isNotBlank(tag)){
                        if(c==0){
                            wrapper1.like(TblXhsEditorTemplateTitle::getTags,"@"+tag+"@");
                            c++;
                        }else{
                            wrapper1.or().like(TblXhsEditorTemplateTitle::getTags,"@"+tag+"@");
                        }
                    }
                }
            });

        }

        wrapper.orderByAsc(TblXhsEditorTemplateTitle::getSort,TblXhsEditorTemplateTitle::getId);
        return mapper.selectList(wrapper);

    }

}
